<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />




  <link rel="icon" type="image/png" sizes="16x16" href="/function%20small()%20%7B%20%5Bnative%20code%5D%20%7D?v=5.1.4">






  <meta name="keywords" content="Minecraft," />




  


  <link rel="alternate" href="/atom.xml" title="chunbingge" type="application/atom+xml" />






<meta name="description" content="大概是上上个月（三月）吧，我忽然有了搭建Minecraft服务器的念头，现在在我的第一篇独立博客中记录一下。服务器可以选择阿里云或腾讯云或别的云服务器或者端口转发。">
<meta property="og:type" content="article">
<meta property="og:title" content="如何搭建一个Minecraft服务器？">
<meta property="og:url" content="https://github.com/chunbingge/2020/build-a-minecraft-server/index.html">
<meta property="og:site_name" content="chunbingge">
<meta property="og:description" content="大概是上上个月（三月）吧，我忽然有了搭建Minecraft服务器的念头，现在在我的第一篇独立博客中记录一下。服务器可以选择阿里云或腾讯云或别的云服务器或者端口转发。">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200408112541228.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwOTc3MjE1,size_16,color_FFFFFF,t_70">
<meta property="article:published_time" content="2020-05-23T12:04:48.000Z">
<meta property="article:modified_time" content="2020-05-24T06:06:06.226Z">
<meta property="article:author" content="Alan Chen">
<meta property="article:tag" content="Minecraft">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/20200408112541228.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwOTc3MjE1,size_16,color_FFFFFF,t_70">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://github.com/chunbingge/2020/build-a-minecraft-server/"/>





  <title>如何搭建一个Minecraft服务器？ | chunbingge</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?02634f722b67f3f480a09b5d8e25cc32";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




<meta name="generator" content="Hexo 4.2.1"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">chunbingge</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">Spring Pancake</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://github.com/chunbingge/2020/build-a-minecraft-server/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Alan Chen">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="chunbingge">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">如何搭建一个Minecraft服务器？</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-05-23T20:04:48+08:00">
                2020-05-23
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%8A%80%E6%9C%AF%E6%80%A7/" itemprop="url" rel="index">
                    <span itemprop="name">技术性</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  2k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  8 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>大概是上上个月（三月）吧，我忽然有了搭建Minecraft服务器的念头，现在在我的第一篇独立博客中记录一下。服务器可以选择阿里云或腾讯云或别的云服务器<del>或者端口转发</del>。</p>
<a id="more"></a>

<h2 id="配置服务器"><a href="#配置服务器" class="headerlink" title="配置服务器"></a>配置服务器</h2><p>本文使用的是<code>CentOS 8.1</code>系统。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">dnf install java</span><br><span class="line">dnf install screen</span><br></pre></td></tr></table></figure>
<p>第一个命令是指安装<code>java</code>（MC必备）；第二个命令是指安装一个叫做<code>screen</code>的软件，用于在远程连接断开的时候不至于服务器关闭。</p>
<p>之后要做的是在服务器里新建一个权限低的叫做minecraft的用户：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">useradd minecraft</span><br></pre></td></tr></table></figure>
<p>表示创建一个名叫mc的用户，但是这个用户还没有密码，所以这样设置：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">passwd minecraft</span><br></pre></td></tr></table></figure>
<p>之后会要求你输入两次新密码</p>
<p>然后在<code>/opt</code>目录下创建一个叫做<code>minecraft_server</code>的文件夹用于存储mc服务器文件并把这个目录的所有者改成刚才创建的minecraft用户：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mkdir /opt/minecraft_server</span><br><span class="line">chown -R minecraft:minecraft /opt/minecraft_server</span><br></pre></td></tr></table></figure>
<h2 id="配置MC服务器"><a href="#配置MC服务器" class="headerlink" title="配置MC服务器"></a>配置MC服务器</h2><p>不管怎么说现在总算是准备妥当。可以配置真正的MC服务器了。<br>首先下载MC服务器版，在你自己电脑的浏览器上打开<a href="https://mcversions.net/" target="_blank" rel="noopener">https://mcversions.net</a>，可以看到各个版本的MC都有，从左到右有四列，分别是：稳定版、快照、beta版和alpha版，推荐选择稳定版（如果要尝试新功能则可以选择其它版本，正常开服的话选稳定版就可以了）。找到你想下载的版本，点击”Download”，之后弹出一个页面，选择”Download Server Jar”。复制下载链接地址。</p>
<p>然后新建一个文件夹（用于在不同时间运行不同版本服务器），下载服务器.jar文件并重命名（如果要配置forge会更方便）：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> /opt/minecraft_server</span><br><span class="line">mkdir &lt;MC版本&gt;</span><br><span class="line"><span class="built_in">cd</span> &lt;MC版本&gt;</span><br><span class="line">wget &lt;下载地址&gt;</span><br><span class="line">mv server.jar minecraft_server.&lt;MC版本&gt;.jar</span><br></pre></td></tr></table></figure>
<p>在开服之前可以通过<code>free</code>命令来查看现在还有多少内存：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">free -h</span><br></pre></td></tr></table></figure>
<p><code>Mem:</code>下的<code>available</code>就代表着现在可用的内存空间。</p>
<p>然后开启服务器：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">java -Xmx512M -jar minecraft_server.&lt;MC版本&gt;.jar nogui</span><br></pre></td></tr></table></figure>
<p>其中<code>-Xmx</code>表示限制Minecraft Server占用的最大内存。</p>
<p>然后等一会，发现会有报错信息，用<code>ls</code>命令可以看到多了一些文件（其中有<code>eula.txt</code>）。把最后一行的<code>false</code>改成<code>true</code>表示同意用户许可。</p>
<p>之后在输入开服指令即可。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim eula.txt</span><br></pre></td></tr></table></figure>
<p>之后再执行一次开服的命令（PS：可以用键盘上的上下键输入之前的命令，文件名输入到一半可以按TAB键来补齐），等几十秒钟可能会看到一些警告提示，可以忽略，之后会有加载地图的进度。完成之后它会提示你已完成。现在输入<code>stop</code>然后回车关掉服务器，我们来配置服务器配置文件。</p>
<p>在<code>server.properties</code>文件中可以更改服务器配置。这里推荐一些要改的设置：</p>
<table>
<thead>
<tr>
<th>参数名及默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>allow-flight=false</td>
<td>最好设置为true，要不然除了创造或观察之外的模式玩家悬空超过5秒就会被自动踢出服务器</td>
</tr>
<tr>
<td>difficulty=0</td>
<td>游戏难度：0-和平，1-简单，2-普通，3-困难</td>
</tr>
<tr>
<td>gamemode=0</td>
<td>默认游戏模式：0-生存，1-创造，2-冒险，3-观察</td>
</tr>
<tr>
<td>level-seed=</td>
<td>生成的地图种子，只有在新建地图之后才有用</td>
</tr>
<tr>
<td>level-name=</td>
<td>生成的地图名称，填上之后会新建一个地图，这时可以指定level-seed</td>
</tr>
<tr>
<td>max-players=20</td>
<td>最大玩家数量，可以根据自己需求来改（小服务器别太大）</td>
</tr>
<tr>
<td>motd=</td>
<td>设置在连接服务器页面的个性化提示语，让你的好友马上就能知道这是你的服务器</td>
</tr>
<tr>
<td>online-mode=true</td>
<td>检查玩家是否为正版用户（我知道很多人像我一样都是盗版用户），所以设置为false（如果为true，那么盗版用户进不了服务器）</td>
</tr>
<tr>
<td>op-permission-level=4</td>
<td>设置op（MC游戏里的管理员）的权限等级，最好设置为2（为2可以使用单人游戏里的所有命令，为4则可以指定op，关闭服务器等），为2只有远程连接到了服务器才可以设置</td>
</tr>
<tr>
<td>view-distance=10</td>
<td>默认加载区块半径，以服务器性能而定</td>
</tr>
</tbody></table>
<p>更多设置参考<a href="https://minecraft-zh.gamepedia.com/Server.properties" target="_blank" rel="noopener">https://minecraft-zh.gamepedia.com/Server.properties</a>。</p>
<h2 id="Systemd"><a href="#Systemd" class="headerlink" title="Systemd"></a>Systemd</h2><p>官方文档推荐写一个启动脚本来运行Minecraft服务器，这里直接采用官方文档。</p>
<p>新建<code>/lib/systemd/system/minecraft@.service</code>文件，写入：</p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Source: https://github.com/agowa338/MinecraftSystemdUnit/</span></span><br><span class="line"><span class="comment"># License: MIT</span></span><br><span class="line"><span class="section">[Unit]</span></span><br><span class="line"><span class="attr">Description</span>=Minecraft Server %i</span><br><span class="line"><span class="attr">After</span>=network.target</span><br><span class="line"></span><br><span class="line"><span class="section">[Service]</span></span><br><span class="line"><span class="attr">WorkingDirectory</span>=/opt/minecraft/%i</span><br><span class="line"><span class="attr">PrivateUsers</span>=<span class="literal">true</span> </span><br><span class="line"><span class="comment"># Users Database is not available for within the unit, only root and minecraft is available, everybody else is nobody</span></span><br><span class="line"><span class="attr">User</span>=minecraft</span><br><span class="line"><span class="attr">Group</span>=minecraft</span><br><span class="line"><span class="attr">ProtectSystem</span>=full </span><br><span class="line"><span class="comment"># Read only mapping of /usr /boot and /etc</span></span><br><span class="line"><span class="attr">ProtectHome</span>=<span class="literal">true</span> </span><br><span class="line"><span class="comment"># /home, /root and /run/user seem to be empty from within the unit. It is recommended to enable this setting for all long-running services (in particular network-facing ones).</span></span><br><span class="line"><span class="attr">ProtectKernelTunables</span>=<span class="literal">true</span> </span><br><span class="line"><span class="comment"># /proc/sys, /sys, /proc/sysrq-trigger, /proc/latency_stats, /proc/acpi, /proc/timer_stats, /proc/fs and /proc/irq will be read-only within the unit. It is recommended to turn this on for most services.</span></span><br><span class="line"><span class="comment"># Implies MountFlags=slave</span></span><br><span class="line"><span class="attr">ProtectKernelModules</span>=<span class="literal">true</span> </span><br><span class="line"><span class="comment"># Block module system calls, also /usr/lib/modules. It is recommended to turn this on for most services that do not need special file systems or extra kernel modules to work</span></span><br><span class="line"><span class="comment"># Implies NoNewPrivileges=yes</span></span><br><span class="line"><span class="attr">ProtectControlGroups</span>=<span class="literal">true</span> </span><br><span class="line"><span class="comment"># It is hence recommended to turn this on for most services.</span></span><br><span class="line"><span class="comment"># Implies MountAPIVFS=yes</span></span><br><span class="line"></span><br><span class="line"><span class="attr">ExecStart</span>=/bin/sh -c <span class="string">'/usr/bin/screen -DmS mc-%i /usr/bin/java -Xmx768M -jar /opt/minecraft/%i/minecraft_server.%i.jar nogui'</span></span><br><span class="line"></span><br><span class="line"><span class="attr">ExecReload</span>=/usr/bin/screen -p <span class="number">0</span> -S mc-%i -X eval <span class="string">'stuff "reload"\\015'</span></span><br><span class="line"></span><br><span class="line"><span class="attr">ExecStop</span>=/usr/bin/screen -p <span class="number">0</span> -S mc-%i -X eval <span class="string">'stuff "say SERVER SHUTTING DOWN. Saving map..."\\015'</span></span><br><span class="line"><span class="attr">ExecStop</span>=/usr/bin/screen -p <span class="number">0</span> -S mc-%i -X eval <span class="string">'stuff "save-all"\\015'</span></span><br><span class="line"><span class="attr">ExecStop</span>=/usr/bin/screen -p <span class="number">0</span> -S mc-%i -X eval <span class="string">'stuff "stop"\\015'</span></span><br><span class="line"><span class="attr">ExecStop</span>=/bin/sleep <span class="number">10</span></span><br><span class="line"></span><br><span class="line"><span class="attr">Restart</span>=<span class="literal">on</span>-failure</span><br><span class="line"><span class="attr">RestartSec</span>=<span class="number">60</span>s</span><br><span class="line"></span><br><span class="line"><span class="section">[Install]</span></span><br><span class="line"><span class="attr">WantedBy</span>=multi-user.target</span><br><span class="line"></span><br><span class="line"><span class="comment">#########</span></span><br><span class="line"><span class="comment"># HowTo</span></span><br><span class="line"><span class="comment">#########</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment"># Create a directory in /opt/minecraft/XX where XX is a name like 'survival'</span></span><br><span class="line"><span class="comment"># Add minecraft_server.jar into dir with other conf files for minecraft server</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment"># Enable/Start systemd service</span></span><br><span class="line"><span class="comment">#    systemctl enable minecraft@survival</span></span><br><span class="line"><span class="comment">#    systemctl start minecraft@survival</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment"># To run multiple servers simply create a new dir structure and enable/start it</span></span><br><span class="line"><span class="comment">#    systemctl enable minecraft@creative</span></span><br><span class="line"><span class="comment"># systemctl start minecraft@creative</span></span><br></pre></td></tr></table></figure>

<p>开启服务器时：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl start minecraft@&lt;MC版本&gt;</span><br></pre></td></tr></table></figure>

<p>关闭服务器时：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl stop minecraft@&lt;MC版本&gt;</span><br></pre></td></tr></table></figure>

<p>加入到开机启动项：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl <span class="built_in">enable</span> minecraft@&lt;MC版本&gt;</span><br></pre></td></tr></table></figure>

<p>这时用版本号命名的优势就体现出来了。可以自由修改上述参数。</p>
<p>官方文档：<a href="https://minecraft-zh.gamepedia.com/%E6%95%99%E7%A8%8B/%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%9E%B6%E8%AE%BE%E8%84%9A%E6%9C%AC" target="_blank" rel="noopener">https://minecraft-zh.gamepedia.com/%E6%95%99%E7%A8%8B/%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%9E%B6%E8%AE%BE%E8%84%9A%E6%9C%AC</a>。</p>
<h2 id="Mod"><a href="#Mod" class="headerlink" title="Mod"></a>Mod</h2><p>想必有些人像我一样喜欢玩有mod的mc，这里也介绍一下。</p>
<p><strong>首先我们需要一个能正常玩的MC服务器，就像上一步的那样去配置！！！</strong></p>
<p>打开<a href="https://files.minecraftforge.net/" target="_blank" rel="noopener">https://files.minecraftforge.net</a>（forge官方网站），之后选择版本，选择下载最上面的最新universal版，点击这个<code>i</code>按钮就可以下载了。复制下载链接：<img src="https://img-blog.csdnimg.cn/20200408112541228.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwOTc3MjE1,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述">然后像之前一样复制下载地址并在mc服务器里的<code>/opt/minecraft_server/&lt;MC版本&gt;/</code>文件夹内输入下载命令（<strong>再次注意：需要这个文件夹里面本来就有一个能正常玩的MC服务器！！！</strong>）：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wget &lt;复制到的下载地址&gt;</span><br></pre></td></tr></table></figure>
<p>然后就下载了带forge的.jar文件。<br>之后需要<code>libraries</code>文件夹，方法有二：</p>
<p>一、从本地的<code>.minecraft</code>文件夹复制到与<code>minecraft_server.&lt;MC版本&gt;.jar</code>同级文件夹下（注意本地要先有服务器上的mc版本）</p>
<p>二、参考<a href="https://www.mcbbs.net/thread-787867-1-1.html" target="_blank" rel="noopener">这篇</a><br>可以用复制下载地址的方式用<code>wget</code>命令下载。</p>
<p>开服的时候把开服命令中的<code>-jar</code>后面的文件名改成刚才下载的带forge的.jar mc文件就行了。第一次开带forge的服的时候会自动在当前目录下会自动生成一个<code>mods</code>文件夹，把要用的mod放进这里面就可以了。注意一些功能性的mod（比如小地图。反正就是没有增加方块或者物品的）别放进去，可能会报错。</p>

      
    </div>
    
    
    

    

    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者：</strong>
    Alan Chen
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://github.com/chunbingge/2020/build-a-minecraft-server/" title="如何搭建一个Minecraft服务器？">https://github.com/chunbingge/2020/build-a-minecraft-server/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>
    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by/4.0/" rel="external nofollow" target="_blank">CC BY 4.0</a> 许可协议。转载请注明出处！
  </li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Minecraft/" rel="tag"># Minecraft</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/remove-zlib-by-mistake/" rel="prev" title="误删zlib">
                误删zlib <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.png"
                alt="Alan Chen" />
            
              <p class="site-author-name" itemprop="name">Alan Chen</p>
              <p class="site-description motion-element" itemprop="description">To be or not to be, that's a question.</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">2</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">1</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">2</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://t.me/chunbingge" target="_blank" title="Telegram">
                      
                        <i class="fa fa-fw fa-telegram"></i>Telegram</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/chunbingge" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:chunbingge@outlook.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#配置服务器"><span class="nav-number">1.</span> <span class="nav-text">配置服务器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#配置MC服务器"><span class="nav-number">2.</span> <span class="nav-text">配置MC服务器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Systemd"><span class="nav-number">3.</span> <span class="nav-text">Systemd</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Mod"><span class="nav-number">4.</span> <span class="nav-text">Mod</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Alan Chen</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

</body>
</html>
